package com.xteam.ecsystem.dao.Impl;

import java.util.Iterator;
import java.util.List;
import java.util.Set;

import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableSheet;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

import com.xteam.ecsystem.dao.initialXlsColumnDao;
import com.xteam.ecsystem.entities.BaseOrderGoods;
import com.xteam.ecsystem.entities.BaseOrderInfo;

public class initOrderXlsColumnDaoImpl implements initialXlsColumnDao {

	@SuppressWarnings("unchecked")
	public void setCellList(List list, WritableSheet wsheet,
			WritableCellFormat wcfFC) throws RowsExceededException,
			WriteException {		
		String orderstate[]={"未确认", "已确认", "无效", "结单", "失效"};
		String distributionState[]={"未配送", "正在配货", "已发货", "已收货", "已退货","无法联系"};
		for (int i = 0; i < list.size(); i++) {
			int j = i + 1;
			BaseOrderInfo orderInfo = (BaseOrderInfo) list.get(i);
			wsheet.addCell(new Label(0, j, orderInfo.getBoiOsn(), wcfFC));
			wsheet.addCell(new Label(1, j, orderInfo.getBoiConsignee(), wcfFC));
			wsheet
					.addCell(new Label(2, j, orderInfo.getBoiMobile(),
							wcfFC));
			wsheet.addCell(new Label(3, j, orderInfo.getBoiOtime().toString(),
					wcfFC));
			wsheet.addCell(new Label(4, j, orderInfo.getBoiDetail(), wcfFC));
			wsheet.addCell(new Label(5, j, orderInfo.getBoiTpay().toString()
					+ "元", wcfFC));
			wsheet.addCell(new Label(6, j, orderstate[orderInfo.getBoiOrder()],
					wcfFC));
			wsheet.addCell(new Label(7, j, distributionState[orderInfo.getBoiShip()],
					wcfFC));
			Set<BaseOrderGoods> goodsSet = orderInfo.getBogList();
			Iterator<BaseOrderGoods> it = goodsSet.iterator();
			StringBuilder str=new StringBuilder();
			while (it.hasNext()) {
				BaseOrderGoods goods = it.next();
				str.append(goods.getBogName()).append(" ").append(goods.getBogNumber()).append("(").append(goods.getBogPrice()).append("元").append("/").append(goods.getBogAttribute()).append(")").append("小计").append(goods.getBogTotal()).append("元").append("; ");
			}
			wsheet.addCell(new Label(8, j, str.toString(), wcfFC));
		}
	}
}
